package com.kotlin.mvpdemo.base;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.viewbinding.ViewBinding;

/**
 * author : fang.zhang
 * e-mail : initzf@126.com
 * date   : 2020/6/6
 * desc   : 建议所有的Fragment 都继承这个BaseFragment
 */
public abstract class BaseFragment<V extends BaseView, T extends BasePresenter<V>, VB extends ViewBinding> extends Fragment implements BaseView {
    protected abstract T getPresenter();

    protected abstract int getLayoutId();

    protected abstract VB getViewBind(LayoutInflater inflater, ViewGroup container);

    protected VB mViewBinding;

    public T mPresenter;


    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        mViewBinding = getViewBind(inflater, container);

        mPresenter = getPresenter();
        mPresenter.onAttach((V) this, this);

        return mViewBinding.getRoot();
    }


    @Override
    public void onDestroy() {
        super.onDestroy();
        mViewBinding = null;
    }
}
